package com.ihisomp.controller;

import com.ihisomp.base.Result;
import com.ihisomp.dto.SysHospitalDto;
import com.ihisomp.dto.SysPathTreeDto;
import com.ihisomp.service.ISysHospitalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 医疗机构信息表 前端控制器
 * </p>
 *
 * @author zy
 * @since 2022-01-12
 */
@RestController
@Api(value = "医疗机构信息", tags = "医疗机构信息")
@RequestMapping("/sysHospital")
public class SysHospitalController {

    Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private ISysHospitalService sysHospitalService;

    /**
     * 获取机构树形集合数据
     *
     * @return
     */
    @GetMapping("/tree")
    @ApiOperation("获取机构树形集合")
    public Result getOrgTree() {
        logger.info("获取机构树形集合数据");
        Result result = sysHospitalService.getOrgTree();
        return result;
    }

    /**
     * 新增数据
     *
     * @param sysHospitalDto
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("新增数据")
    @ApiImplicitParam(name = "sysHospitalDto", value = "机构数据类", required = true)
    public Result add(@RequestBody SysHospitalDto sysHospitalDto) {
        logger.info("新增数据：sysHospitalDto={}", sysHospitalDto);
        Result result = sysHospitalService.add(sysHospitalDto);
        return result;
    }

    /**
     * 更新状态
     *
     * @param orgKey
     * @param status
     * @return
     */
    @PostMapping("status/{orgKey}/{status}")
    @ApiOperation("更新状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orgKey", value = "机构主键", required = true),
            @ApiImplicitParam(name = "status", value = "状态代码", required = true)})
    public Result updateStatus(@PathVariable("orgKey") String orgKey,
                               @PathVariable("status") int status) {
        logger.info("更新状态：orgKey={}, status={}", orgKey, status);
        Result result = sysHospitalService.updateStatus(orgKey, status);
        return result;
    }

    /**
     * 更新数据
     *
     * @param orgKey
     * @param sysHospitalDto
     * @return
     */
    @PostMapping("/update/{orgKey}")
    @ApiOperation("更新数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orgKey", value = "机构主键", required = true),
            @ApiImplicitParam(name = "sysHospitalDto", value = "机构数据类", required = true)})
    public Result update(@PathVariable("orgKey") String orgKey, @RequestBody SysHospitalDto sysHospitalDto) {
        logger.info("更新数据：orgKey={}, sysHospitalDto={}", orgKey, sysHospitalDto);
        Result result = sysHospitalService.update(orgKey, sysHospitalDto);
        return result;
    }

    /**
     * 查询数据
     *
     * @param orgKey
     * @return
     */
    @GetMapping("/get/{orgKey}")
    @ApiOperation("查询数据")
    @ApiImplicitParam(name = "orgKey", value = "机构主键", required = true)
    public Result get(@PathVariable("orgKey") String orgKey) {
        logger.info("查询数据：orgKey={}", orgKey);
        Result result = sysHospitalService.get(orgKey);
        return result;
    }

    /**
     * 分页查询
     *
     * @param page
     * @param size
     * @param sysHospitalDto
     * @return
     */
    @PostMapping("/search/{page}/{size}")
    @ApiOperation("分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码", required = true),
            @ApiImplicitParam(name = "size", value = "每页条数", required = true),
            @ApiImplicitParam(name = "sysHospitalDto", value = "机构数据类", required = true)})
    public Result search(@PathVariable("page") long page,
                         @PathVariable("size") long size,
                         @RequestBody(required = false) SysHospitalDto sysHospitalDto) {
        logger.info("分页查询：page={}, size={}, sysHospitalDto={}", size, size, sysHospitalDto);
        Result result = sysHospitalService.search(page, size, sysHospitalDto);
        return result;
    }

    /**
     * 管理公司列表
     *
     * @return
     */
    @GetMapping("/selectManageList")
    @ApiOperation("管理公司数据")
    public Result selectManageList() {
        logger.info("管理公司列表");
        Result result = sysHospitalService.selectManageList();
        return result;
    }

    /**
     * 查询机构程序权限
     *
     * @param orgKey
     * @return
     */
    @GetMapping("/getOrgPath/{orgKey}")
    @ApiOperation("查询机构菜单权限")
    @ApiImplicitParam(name = "orgKey", value = "机构主键", required = true)
    public Result getOrgPath(@PathVariable("orgKey") String orgKey) {
        logger.info("查询机构程序权限：orgKey={}", orgKey);
        Result result = sysHospitalService.getPathByOrgKey(orgKey);
        return result;
    }

    /**
     * 更新机构程序权限
     *
     * @param orgKey
     * @param orgPathList
     * @return
     */
    @PostMapping("/updateOrgPath/{orgKey}")
    @ApiOperation("更新机构菜单权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orgKey", value = "机构主键", required = true),
            @ApiImplicitParam(name = "orgPathList", value = "机构菜单数据类", required = true)})
    public Result updateOrgPath(@PathVariable("orgKey") String orgKey, @RequestBody List<SysPathTreeDto> orgPathList) {
        logger.info("更新机构程序权限：orgKey={}, orgPathList={}", orgKey, orgPathList);
        Result result = sysHospitalService.updateOrgPath(orgKey, orgPathList);
        return result;
    }


    /**
     * 查询机构程序权限树形数据
     *
     * @param orgKey
     * @return
     */
    @GetMapping("/getOrgPathTree/{orgKey}")
    @ApiOperation("查询机构菜单权限树形数据")
    @ApiImplicitParam(name = "orgKey", value = "机构主键", required = true)
    public Result getOrgPathTree(@PathVariable("orgKey") String orgKey) {
        logger.info("查询机构程序权限树形数据：orgKey={}", orgKey);
        Result result = sysHospitalService.getOrgPathTree(orgKey);
        return result;
    }
}
